<?php namespace Reezy\APISign;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;

class APISignMiddleware implements MiddlewareInterface
{
    /**
     * @var APISignManager
     */
    private $manager;

    public function __construct(APISignManager $manager)
    {
        $this->manager = $manager;
    }

    /**
     * Process an incoming server request.
     *
     * @param ServerRequestInterface $request
     * @param RequestHandlerInterface $handler
     *
     * @return ResponseInterface
     */
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $this->manager->check($request);

        return $handler->handle($request);
    }

}
